package com.youhome.clients.controller;

import com.youhome.clients.dto.DTOAppointmentHouse;
import com.youhome.common.exception.CustomException;
import com.youhome.common.response.Result;
import com.youhome.common.response.ResultCode;
import com.youhome.service.parameter.ParamAppointmentHouse;
import com.youhome.service.service.HouseAppointmentService;
import io.swagger.annotations.*;
import org.modelmapper.ModelMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by chen365 on 2018/03/13.
 */
@RestController
@RequestMapping(value = "/appointment")
@Api(tags = "看房预约")
public class HouseAppointmentController {

    @Autowired
    private HouseAppointmentService houseAppointmentService;


    @ApiOperation(value = "看房预约", notes = "看房预约", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "String", name = "msg", value = "短信码", required = true, paramType = "query"),
            @ApiImplicitParam(dataType = "String", name = "msgId", value = "短信码ID", required = true, paramType = "query"),
            @ApiImplicitParam(dataType = "String", name = "phone", value = "手机号", required = true, paramType = "query"),
            @ApiImplicitParam(dataType = "String", name = "name", value = "姓名", required = true, paramType = "query"),
            @ApiImplicitParam(dataType = "String", name = "appointmentTime", value = "看房时间", required = true, paramType = "query"),
            @ApiImplicitParam(dataType = "String", name = "type", value = "看房方式", required = true, paramType = "query"),
    })
    @PostMapping(value = "/house")
    public Object appointmentHouse(@ApiParam @Validated DTOAppointmentHouse dtoAppointmentHouse) throws CustomException {
        ModelMapper modelMapper = new ModelMapper();
        houseAppointmentService.appointmentHouse(modelMapper.map(dtoAppointmentHouse, ParamAppointmentHouse.class));
        return new Result(ResultCode.SUCCESS);
    }
}
